package date0708pm;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesTest3 {

	public static void main(String[] args) throws IOException {
		
		final String driverPattern = "jdbc.connection..driver";
		
		PropertiesTest3 pt = new PropertiesTest3();
		
		String propName = pt.x( driverPattern , "mysql" );
		System.out.println( propName );
		
		Properties properties = new Properties();
		InputStream in = PropertiesTest3.class.getResourceAsStream( "/jdbc.properties");
		properties.load( in );
		in.close();
		
		String propValue = properties.getProperty( propName ); // 根据属性名获取属性值
		System.out.println( propValue );

	}
	
	final StringBuffer buffer = new StringBuffer();
	
	public String x( String pattern , String name ) {
		buffer.setLength(0); // "重置" 字符串缓冲区
		buffer.append( pattern ); // 将 driverPattern 添加到字符串缓冲区
		int last = buffer.lastIndexOf("."); // 获取最后一个圆点的索引值
		buffer.insert( last , name ); // 插入数据库名称
		return buffer.toString();
	}

}
